package com.adnaan.admin.service.impl;

import com.adnaan.admin.mapper.SysUserMapper;
import com.adnaan.admin.model.entity.SysUser;
import com.adnaan.admin.service.SysUserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 系统用户服务实现类
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {

    /**
     * 通过用户名查询用户
     *
     * @param username 用户名
     * @return 用户对象
     */
    @Override
    public SysUser getByUsername(String username) {
        LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysUser::getUsername, username);
        return getOne(queryWrapper);
    }

    /**
     * 查询用户角色列表
     *
     * @param userId 用户ID
     * @return 角色标识列表
     */
    @Override
    public Set<String> getRoleKeys(Long userId) {
        List<String> roleKeys = baseMapper.selectRoleKeysByUserId(userId);
        Set<String> roles = new HashSet<>(roleKeys);
        return roles;
    }

    /**
     * 查询用户权限列表
     *
     * @param userId 用户ID
     * @return 权限标识列表
     */
    @Override
    public Set<String> getPermissions(Long userId) {
        List<String> permissions = baseMapper.selectPermissionsByUserId(userId);
        Set<String> perms = new HashSet<>(permissions);
        return perms;
    }
} 